﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace skald_db
{
    public static class Config
    {
        private static string in_workstation;
        private static string in_initial_catalog;
        private static string in_last_used_connection_string;
        private static string in_last_used_database;
        public static bool save_records() {

            return true;
        }
        public static string WorkstationId
        {
            get { return in_workstation; }
            set { in_workstation = value; }
        }
        public static string InitialCatalog
        {
            get { return in_initial_catalog; }
            set { in_initial_catalog = value; }
        }
        public static string LastUsedConnectionString
        {
            get { return in_last_used_connection_string; }
            set { in_last_used_connection_string = value; }
        }
        public static string LastUsedDatabase
        {
            get { return in_last_used_database; }
            set { in_last_used_database = value; }
        }
        public static bool LoadSettings()
        {
            bool res = false;
            string s = "";
            try
            {
                using (StreamReader sr = File.OpenText(@"cfg\options.ini"))
                {
                    in_workstation = sr.ReadLine();
                    while (in_workstation[0] == '/')
                    {
                        in_workstation = sr.ReadLine();
                    }
                    in_initial_catalog = sr.ReadLine();
                    while (in_initial_catalog[0] == '/')
                    {
                        in_initial_catalog = sr.ReadLine();
                    }
                    in_last_used_connection_string = sr.ReadLine();
                    while (in_last_used_connection_string[0] == '/')
                    {
                        in_last_used_connection_string = sr.ReadLine();
                    }
                    in_last_used_database = sr.ReadLine();
                    while (in_last_used_database[0] == '/')
                    {
                        in_last_used_database = sr.ReadLine();
                    }
                }
                res = true;
            }
            catch (Exception ex)
            {
                res = false;
                MessageBox.Show(ex.Message);
            }
            return res;
        }
        public static bool SaveSettings()
        {
            bool res = false;
            string s = in_workstation + "/n" + in_initial_catalog + "/n" + in_last_used_connection_string + "/n" + in_last_used_database;
            try
            {
                File.WriteAllText(@"cfg\options.ini", s);
                res = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                res = false;
            }
            return res;
        }
    }
    public class file_work 
    {

        
        public bool load_options()
        {
            //Program.global_conn_str = "workstation id=cybernet.mssql.somee.com;packet size=4096;user id=posedge_SQLLogin_1;pwd=1oq658z9od;data source=cybernet.mssql.somee.com;persist security info=False;";
            //Program.global_db_name = "cybernet";
            Program.global_conn_str = @"Data Source=NADEJDA\SQLEXPRESS;Integrated Security=True;";
            Program.global_db_name = "anton";
            return true;
        }


    }
}
